<template>
  <div class="article" style="line-height: 40px">
    <!-- 文章列表 -->
    <h1
      style="height: 60px; line-height: 60px; font-size: 20px; text-align: left"
    >
      文章列表
    </h1>
    <el-button type="primary" round style="text-align: left" @click="handleNew"
      >新建文章</el-button
    >
    <el-table
      :data="[...tableData, ...tableData, ...tableData]"
      style="line-height: 20px !important"
      stripe
      border
    >
      <el-table-column label="#" width="180" prop="id"></el-table-column>

      <el-table-column label="标题" width="300" prop="title"></el-table-column>

      <el-table-column label="封面" width="180" prop="">
        <template slot-scope="scope">
          <img :src="scope.row.poster" width="40" />
        </template>
      </el-table-column>

      <el-table-column label="类型" width="180" prop="type"></el-table-column>

      <el-table-column
        label="发布者"
        width="180"
        prop="author"
      ></el-table-column>

      <el-table-column
        label="创建时间"
        width="200"
        prop="created_at"
      ></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleDetail(scope.$index, scope.row)"
            type="success"
            icon="el-icon-view"
            circle
          ></el-button>

          <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)"
            type="primary"
            icon="el-icon-edit"
            circle
          ></el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            icon="el-icon-delete"
            circle
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      tableData: [],
    };
  },
  methods: {
    handleDetail(index, row) {
      this.$router.push({
        name: "AdminArticleDetail",
        params: {
          article_id: row.id,
        },
      });
    },
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row.id);
      axios
        .delete("http://120.27.209.174:1010/api/v1/posts", {
          params: {
            id: row.id,
          },
        })
        .then((res) => {
          console.log(res);
        });
    },
    handleNew() {
      console.log("00000");
      this.$router.push({
        name: "AdminArticleNew",
      });
    },
  },
  created() {
    axios({
      url: "http://120.27.209.174:1010/api/v1/posts",
    }).then((res) => {
      console.log(res.data.data);
      this.tableData = res.data.data;
    });
  },
};
</script>

<style scoped>
* {
  margin: 0;
  pading: 0;
}
b {
  line-height: 80px !important;
  height: 80px;
}
</style>
